'''
购物车模块用例
共分为 增删改查
该 case为 删除购物车
'''
import unittest
from common.Base import Base, open_browser
from Page.shopping_process_page import shopping_process
from common.databaseTool import DatabaseTool
import hashlib

# 登录页面url
url = "http://localhost:8080/ecshop/user.php"


class Shopingcart_case(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.data = DatabaseTool("168168", "ecshop_db", port=3308)
        sql = f"insert into ecs_users (user_name,password) values ('test','{hashlib.md5(b'111111').hexdigest()}')"
        cls.data.execute_one(sql)

    @classmethod
    def tearDownClass(cls):
        sql = "delete from ecs_users where user_name like '%test%'"
        cls.data.execute_one(sql)

    def setUp(self):
        pass
        # 每一个用例执行前执行 准备测试数据
        op = open_browser()
        self.shop = shopping_process(op)
        self.shop.open_url(url)
        self.shop.input_username("test")
        self.shop.input_password("111111")
        self.shop.click_submit()
        self.shop.click_homepage()

    def tearDown(self):
        # 每一个用例执行后执行 清除环境
        # 关闭浏览器
        self.shop.quit()
        pass

    def test_shopping_add_017(self):
        # 点击智能相机商品
        self.shop.click_Smartcamera()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除智能相机
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

    def test_shopping_add_018(self):
        # 点击炫彩翻页保护套商品
        self.shop.click_Colorfulflipcover()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除炫彩翻页保护套
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

    def test_shopping_add_019(self):
        # 点击平衡车商品
        self.shop.click_Balanceofthecar()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除平衡车
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

    def test_shopping_add_020(self):
        # 点击透明超薄软胶保护套商品
        self.shop.click_superProtectivesleeve()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除透明超薄软胶保护套商品
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

    def test_shopping_add_021(self):
        # 点击运动相机商品
        self.shop.click_Sportscamera()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除运动相机
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

    def test_shopping_add_022(self):
        # 点击自拍杆商品
        self.shop.click_Sincetheshaft()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除自拍杆
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

    def test_shopping_add_023(self):
        # 点击随身风扇商品
        self.shop.cilck_Keepthefan()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除随身风扇
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

    def test_shopping_add_024(self):
        # 点击视频商品
        self.shop.click_video()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 删除商品
        self.shop.click_del_good()
        # 点击确定
        self.shop.click_window()
        # 判断购物车金额是否减少
        money = self.shop.git_shoppingcart_money()
        self.assertIn("0.00", money, "用例执行失败购物车金额未减少")

